
#include "IrrCompileConfig.h"

#include "CReader.h"

#ifdef DELPHI_WRAP

namespace irr
{
namespace io
{

// ======= class CReader =======
CReader::CReader(const io::path& path, bool ignoreCase, bool ignorePaths)
: CFileList(path, ignoreCase, ignorePaths)
{
	m_Archive = new CWrapFileArchive(this);
}

CReader::~CReader(void)
{
	if (m_Archive)
	{
		delete m_Archive;
		m_Archive = 0;
	}
}

// ======= class CWrapFileArchive =======
CWrapFileArchive::CWrapFileArchive(CReader *OwnerReader)
{
	m_OwnerReader = OwnerReader;
}

CWrapFileArchive::~CWrapFileArchive()
{
	if (m_OwnerReader)
	{
		m_OwnerReader->m_Archive = 0;
		delete m_OwnerReader;
		m_OwnerReader = 0;
	}
}

IReadFile* CWrapFileArchive::createAndOpenFile(const path& filename)
{
	return m_OwnerReader->createAndOpenFile(filename);
}

IReadFile* CWrapFileArchive::createAndOpenFile(u32 index)
{
	return m_OwnerReader->createAndOpenFile(index);
}

const IFileList* CWrapFileArchive::getFileList() const
{
	return m_OwnerReader->getFileList();
}

E_FILE_ARCHIVE_TYPE CWrapFileArchive::getType() const
{
	return m_OwnerReader->getType();
}

#endif

} // end namespace io
} // end namespace irr